package com.myidis.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.myidis.entity.AnalysisResult;
import com.myidis.entity.User;

public interface AnalysisResultMapper {
	@Select("SELECT * FROM quota_analysis")
    @Results({
    	@Result(property = "analysisType", column = "analysis_type"),
        @Result(property = "startTime", column = "start_time"),
        @Result(property = "endTime", column = "end_time")
    })
    List<AnalysisResult> all();
	
	@Select("SELECT * FROM quota_analysis WHERE baseQuota = #{baseQuota}")
    @Results({
    	@Result(property = "analysisType", column = "analysis_type"),
        @Result(property = "startTime", column = "start_time"),
        @Result(property = "endTime", column = "end_time")
    })
	List<AnalysisResult> getByBase(int baseQuota);

	@Select("SELECT * FROM quota_analysis WHERE baseQuota = #{baseQuota}")
    @Results({
    	@Result(property = "analysisType", column = "analysis_type"),
        @Result(property = "startTime", column = "start_time"),
        @Result(property = "endTime", column = "end_time")
    })
	List<AnalysisResult> getByCon(AnalysisResult con);
	
    @Select("SELECT * FROM quota_analysis WHERE id = #{id}")
    @Results({
    	@Result(property = "analysisType", column = "analysis_type"),
        @Result(property = "startTime", column = "start_time"),
        @Result(property = "endTime", column = "end_time")
    })
    AnalysisResult getOne(int id);

    @Insert("INSERT INTO quota_analysis(baseQuota, analysisQuota, analysis_type, start_time, end_time, result, analyst) VALUES(#{baseQuota}, #{analysisQuota}, #{analysisType}, #{startTime}, #{endTime}, #{result} , #{analyst})")
    int insert(AnalysisResult analysis);

    @Update("UPDATE quota_analysis SET baseQuota = #{baseQuota}, analysisQuota = #{analysisQuota}, analysis_type = #{analysisType}, start_time = #{startTime}, end_time = #{endTime}, result = #{result}, analyst = #{analyst} WHERE id = #{id}")
    int update(AnalysisResult analysis);

    @Delete("DELETE FROM quota_analysis WHERE id = #{id}")
    int delete(int id);
}
